package com.chinasofti.method2;
import java.lang.reflect.Method;

public class TestMethodDemo {
    public static void main(String[] args) throws ClassNotFoundException, NoSuchMethodException {
        //method1();
        //method2();
        //method3();
        //method4();
        Class clazz = Class.forName("com.chinasofti.ref.method2.Student");
        //获取私有方法
        Method method = clazz.getDeclaredMethod("show");
        System.out.println(method);
    }

    private static void method4() throws ClassNotFoundException, NoSuchMethodException {
        Class clazz = Class.forName("com.chinasofti.ref.method2.Student");
        //获取一个有形参的方法
        Method method2 = clazz.getMethod("function2",String.class);

        System.out.println(method2);
    }

    private static void method3() throws ClassNotFoundException, NoSuchMethodException {
        Class clazz = Class.forName("com.chinasofti.ref.method2.Student");
        Method method1 = clazz.getMethod("function1");

        System.out.println(method1);
    }

    private static void method2() throws ClassNotFoundException {
        Class clazz = Class.forName("com.chinasofti.ref.method2.Student");
        Method[] declaredMethods = clazz.getDeclaredMethods();//获取全部成员方法
        for(Method method : declaredMethods){
            System.out.println(method);
        }
    }

    private static void method1() throws ClassNotFoundException {
        //getMethods
        Class clazz = Class.forName("com.chinasofti.ref.method2.Student");
        //获取成员方法
        Method[] methods = clazz.getMethods();
        for(Method method:methods){
            System.out.println(method);
        }
    }
}